import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import {createStore} from "vuex";
import ElementPlus, {ElMessage} from 'element-plus'
import axios from "axios";
const store = createStore({
    state () {
        return {
            account: 0,
            records:[],
            recordsId:0,
            message:[],
            isLoading:false
        }
    },
    mutations: {
        setAccount (state,acc) {
            state.account=acc
        },
        setRecords (state,records){
            state.records=records

        },
        setMessage(state,message){
            state.message=message
        },
        addMessage(state,message){
            for (let key in message) {
                store.state.message.push(message[key])
            }
        },
        setRecordsId(state,id){
            state.recordsId=id
            axios.get("http://localhost:20247/records/getAllRecordsItemById", {
                params: {
                    id: store.state.recordsId
                }
            }).then((response) => {
                if (response.data.success === true) {
                    store.commit('setMessage',response.data.data.recordsItem)
                } else {
                    store.commit('setMessage',[])
                    console.log("setRecordsId error")
                }
            }).catch(() => {

            })
        }


    }
})
createApp(App).use(store)
    .use(router).use(ElementPlus)
    .mount('#app');
